#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <wctype.h>
#include <assert.h>

#ifdef __cplusplus
extern "C" {
#endif

int compare_hex(const uint8_t *h1, const uint8_t *h2, int n)
{
    assert(0 != n);
    assert(NULL != h1);
    assert(NULL != h2);
    while(--n && (*h1 == *h2))
    {
        h1++; h2++;
    }
    return *h1 - *h2;
}

int compare_str(const char *s1, const char *s2)
{
    assert(NULL != s1);
    assert(NULL != s2);
    while(*s1 && (*s1 == *s2))
    {
       s1++; s2++;
    }
    return *s1 - *s2;
}

int compare_str_ignore_case(const char *s1, const char *s2)
{
    assert(NULL != s1);
    assert(NULL != s2);
    while(*s1 && (towlower(*s1) == towlower(*s2)))
    {
       s1++; s2++;
    }
    return towlower(*s1) - towlower(*s2);
}

int compare_nstr(const char *s1, const char *s2, int n)
{
    assert(0 != n);
    assert(NULL != s1);
    assert(NULL != s2);
    while(--n && *s1 && (*s1 == *s2))
    {
        s1++; s2++;
    }
    return *s1 - *s2;
}

int compare_nstr_ignore_case(const char *s1, const char *s2, int n)
{
    assert(0 != n);
    assert(NULL != s1);
    assert(NULL != s2);
    while(--n && *s1 && (towlower(*s1) == towlower(*s2)))
    {
        s1++; s2++;
    }
    return towlower(*s1) - towlower(*s2);
}

#ifdef __cplusplus
}
#endif
